package com.example.controller;

import com.example.common.Result;
import com.example.entity.Major;
import com.example.service.MajorService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/major")
public class MajorController {
    @Resource
    private MajorService majorService;

    @GetMapping("/selectAll")
    public Result selectAll(Major major){
        List<Major> list = majorService.selectAll(major);
        return Result.success(list);
    }

    @GetMapping("/selectPage")
    public Result selectPage(Major major,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<Major> pageInfo = majorService.selectPage(major,pageNum,pageSize);
        return Result.success(pageInfo);
    }
    @PostMapping("/insert")
    public Result add(@RequestBody Major major){
        majorService.add(major);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Major major){
        majorService.update(major);
        return Result.success();
    }

    @DeleteMapping("/delete/{majorId}")
    public Result delete(@PathVariable Integer majorId){
        majorService.delete(majorId);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        majorService.deleteBatch(ids);
        return Result.success();
    }
}
